package com.sskj.aikeeper.hangqing.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.aikeeper.R;
import com.sskj.aikeeper.bean.CetificationBean;
import com.sskj.aikeeper.presenter.CertificationResultPresenter;
import com.sskj.common.base.App;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.SPConfig;
import com.sskj.lib.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/06/25
 */
@Route(path = RConfig.APP_ACTIVITY_CERTIFICATION_RESULT)
public class CertificationResultActivity extends BaseActivity<CertificationResultPresenter> {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.iv_status)
    ImageView ivStatus;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_msg)
    TextView tvMsg;
    @Autowired
    int certificationResult;

    @Override
    public int getLayoutId() {
        return R.layout.app_activity_certification_result;
    }

    @Override
    public CertificationResultPresenter getPresenter() {
        return new CertificationResultPresenter();
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
//        switch (certificationResult) {
//            case Constans.CERTIFICATION_LOADING:
//                tvTitle.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity1));
//                ivStatus.setImageResource(R.mipmap.icon_renzheng_loading);
//                tvStatus.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity2));
//                tvMsg.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity3));
//                break;
//            case Constans.CERTIFICATION_SUCCESS:
//                tvTitle.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity4));
//                ivStatus.setImageResource(R.mipmap.icon_renzheng_suceess);
//                tvStatus.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity5));
//                tvMsg.setText("");
//                break;
//            case Constans.CERTIFICATION_FAIL:
//                tvTitle.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity6));
//                SpannableString spannableString = new SpannableString(App.INSTANCE.getString(R.string.app_certificationResultActivity7));
//                ClickableSpan clickableSpan = new ClickableSpan() {
//                    @Override
//                    public void updateDrawState(@NonNull TextPaint ds) {
//                        ds.setColor(ContextCompat.getColor(CertificationResultActivity.this, R.color.lib_theme));
//                    }
//
//                    @Override
//                    public void onClick(@NonNull View widget) {
//                        ARouter.getInstance().build(RConfig.APP_ACTIVITY_CERTIFICATION).navigation();
//                    }
//                };
//                spannableString.setSpan(clickableSpan, spannableString.toString().indexOf("，") + 1, spannableString.toString().indexOf("！"), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
//                tvStatus.setText(spannableString);
//                tvStatus.setMovementMethod(new LinkMovementMethod());
//                ivStatus.setImageResource(R.mipmap.icon_renzheng_fail);
//                tvMsg.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity8));
//                break;
//        }
    }

    @Override
    public void initData() {
        mPresenter.getCertificationStatus();

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, CertificationResultActivity.class);
        context.startActivity(intent);
    }

    public void getStatusOK(CetificationBean data) {
        if (data == null) {
            return;
        }
        SPUtil.put(SPConfig.CETIFICATION, data.getStatus());
        switch (data.getStatus()) {
            case Constans.CERTIFICATION_LOADING:
                tvTitle.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity1));
                ivStatus.setImageResource(R.mipmap.icon_renzheng_loading);
                tvStatus.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity2));
                tvMsg.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity3));
                break;
            case Constans.CERTIFICATION_SUCCESS:
                tvTitle.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity4));
                ivStatus.setImageResource(R.mipmap.icon_renzheng_suceess);
                tvStatus.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity5));
                tvMsg.setText("");
                break;
            case Constans.CERTIFICATION_FAIL:
                tvTitle.setText(App.INSTANCE.getString(R.string.app_certificationResultActivity6));
                SpannableString spannableString = new SpannableString(App.INSTANCE.getString(R.string.app_certificationResultActivity7));
                ClickableSpan clickableSpan = new ClickableSpan() {
                    @Override
                    public void updateDrawState(@NonNull TextPaint ds) {
                        ds.setColor(ContextCompat.getColor(CertificationResultActivity.this, R.color.lib_theme));
                    }

                    @Override
                    public void onClick(@NonNull View widget) {
                        ARouter.getInstance().build(RConfig.APP_ACTIVITY_CERTIFICATION).navigation();
                        finish();
                    }
                };
                spannableString.setSpan(clickableSpan, spannableString.toString().indexOf("，") + 1, spannableString.toString().indexOf("！"), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
                tvStatus.setText(spannableString);
                tvStatus.setMovementMethod(new LinkMovementMethod());
                ivStatus.setImageResource(R.mipmap.icon_renzheng_fail);
                tvMsg.setText(data.getMsg());
                break;
        }

    }
}
